package com.mxx.common.generator.db;

import com.mxx.common.core.UniquelyList;
import com.mxx.common.utils.Strings;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class Table {

    private String database;

    private String tableName;

    private String remark;

    private String tableType;

    private UniquelyList<String, TableColumn> tableColumnList = new UniquelyList<>(TableColumn::getColumnName);


    public Table addTableField(TableColumn tableColumn) {
        this.tableColumnList.add(tableColumn);
        return this;
    }

    public TableColumn getField(String fieldName) {
        return tableColumnList.getByKey(fieldName);
    }

    @Override
    public String toString() {
        return tableName + (Strings.isEmpty(remark) ? "" : " (" + remark + ")");
    }
}
